import path from 'path'
import { defineConfig, loadEnv } from 'vite'
// import { MarkdownTransform } from './.vitepress/plugins/markdown-transform'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueSetupExtend from 'vite-plugin-vue-setup-extend' // 设置neme属性

import type { Alias } from 'vite'

const alias: Alias[] = [
  {
    find: '~/',
    replacement: `${path.resolve(__dirname, './.vitepress/vitepress')}/`,
  },
]
if (process.env.DOC_ENV !== 'production') {
  alias.push(
    {
      find: /^element-plus(\/(es|lib))?$/,
      replacement: path.resolve('../', 'packages/element-plus/index.ts'),
    },
    {
      find: /^element-plus\/(es|lib)\/(.*)$/,
      replacement: `${path.resolve('../', 'packages')}/$2`,
    }
  )
}

export default defineConfig(async ({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')

  return {
    plugins: [vueJsx(), vueSetupExtend()], // MarkdownTransform(),
    resolve: {
      // alias,
    },
    server: {
      host: '0.0.0.0',
      https: false,
    },
  }
})
